#pragma once

#include "FastSerial.h"
#include <Arduino.h>
#include "RC.h"
#include "Sensors.h"
#include "Ap.h"
#include "AP_IMU.h"
#include "AP_DCM.h"
#include "myGps.h"

class Aircraft
{
private:
	RC1 *rc;//TEMP
	
	int _in[8];
	int _out[4];
	
	int servoMax[4];
	int servoMin[4];
	bool servoInv[4];
	
	void mapServo(int num, int defl);
	
public:
	Aircraft();
	
	Ap ap;
	Sensors sensors;
	
	void updateRCin();
	void updateRCout();
	
	void init(RC1 *sysrc, AP_PeriodicProcess *pdpr, AP_IMU_INS &imu, AP_DCM &dcm, MyGPS &gps);
	void update();
	int RCin(int ch);
	void RCout(int ch, int val);
	int getRCout(int ch);
	void runOffInputs();
	void myDelay(unsigned long t);
	
	void updateCalibration();
	
	void servoTest();
	void svoRoll(int defl);//-100 to 100 ... + right / - left
	void svoPitch(int defl);//-100 to 100 ... + up / - down
	void throttleCmd(int power);//0 to 100 ... 0 off / 100 full
	void svoRudder(int defl);//-100 to 100 ... + right / - left
	
	void svoInvert(int ch);
	void svoInvert(int ch, bool to);
	bool svoGetInvert(int ch);
	int getSvoMin(int ch);
	int getSvoMax(int ch);
	void setSvoMax(int ch, int to);
	void setSvoMin(int ch, int to);
	void saveSvoPresets();
	void setSvoRange(int ch, int min, int max);
};
